//
//  ExaminaExamineController.m
//  Coach_HaiGeEr
//
//  Created by liuchen on 2018/10/19.
//  Copyright © 2018年 海格尔. All rights reserved.
//

#import "ExaminaExamineController.h"
#import "ExaminaColumnView.h"
#import "ExaminaWaitExamineController.h"
#import "ExaminaAlreadyExamineController.h"

@interface ExaminaExamineController ()
@property (nonatomic,strong) ExaminaColumnView *indicatorView;
@property (nonatomic,strong) ExaminaWaitExamineController *waitVC;
@property (nonatomic,strong) ExaminaAlreadyExamineController *alreadyVC;
@end

@implementation ExaminaExamineController

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [[CoachTabBarController shareLZHTabbarController].tabBar setHidden:YES];
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createSubView];
}

#pragma mark ==========创建视图==========
- (void)createSubView{
    self.title = self.state==1?@"教练审核":@"驾校审核";
    self.view.backgroundColor = [UIColor whiteColor];
    [self setNavBack];
    
    self.waitVC = [[ExaminaWaitExamineController alloc] init];
    self.waitVC.state = self.state;
    [self addChildViewController:self.waitVC];
    
    self.alreadyVC = [[ExaminaAlreadyExamineController alloc] init];
    self.alreadyVC.state = self.state;
    [self addChildViewController:self.alreadyVC];
    
    self.indicatorView = [[ExaminaColumnView alloc] initWithFrame:CGRectMake(0, SYSTEM_TOP, SCREEN_WIDTH, SCREEN_HEIGHT-SYSTEM_TOP) WithTitle:@[@"待审核",@"已审核"]];
    [self.view addSubview:self.indicatorView];

    CGFloat wid = self.indicatorView.contentSrcView.frame.size.width;
    CGFloat hei = self.indicatorView.contentSrcView.frame.size.height;
    self.waitVC.view.frame = CGRectMake(0, 0, wid, hei);
    self.waitVC.tableView.frame = CGRectMake(0, 0, wid, hei-200*SCALEUNIT);
    [self.indicatorView.contentSrcView addSubview:self.waitVC.view];
    self.alreadyVC.view.frame = CGRectMake(wid, 0, wid, hei);
    self.alreadyVC.tableView.frame = CGRectMake(0, 0, wid, hei-200*SCALEUNIT);
    [self.indicatorView.contentSrcView addSubview:self.alreadyVC.view];

    //kvo
    [self.waitVC addObserver:self forKeyPath:@"refreshNum" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:nil];
}

#pragma mark ==========观察者==========
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context{
    if ([keyPath isEqualToString:@"refreshNum"]) {
        [self.alreadyVC loadData];
    }
}

- (void)dealloc{
    [self.waitVC removeObserver:self forKeyPath:@"refreshNum"];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
